package com.luoxiang.socialandroid.adapter

import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.luoxiang.socialandroid.R
import com.luoxiang.socialandroid.bean.ListDetail
import com.luoxiang.socialandroid.common.Constants
import com.luoxiang.socialandroid.utils.MmkvUtil

/**
 * Author: fuxinbo

 * Date: 2023/2/9

 * Description: 邀请榜单适配器
 */
class InviteListAdapter : BaseQuickAdapter<ListDetail, BaseViewHolder>(R.layout.item_invite_list) {

    override fun convert(holder: BaseViewHolder, item: ListDetail) {
        holder.run {
            setText(R.id.textIndex, (holder.layoutPosition + 4).toString())
            setText(R.id.textName, item.name)
            setText(R.id.textReward, "奖励：${item.reward}积分")
            setText(R.id.textReceive1, if (item.status == 0) "已领取" else "未领取")
            holder.setBackgroundResource(
                R.id.textReceive1,
                if (item.status == 0) R.drawable.bg_list_item_receive else R.drawable.bg_list_item_no_receive
            )
            holder.setTextColor(
                R.id.textReceive1,
                if (item.status == 0)
                    ContextCompat.getColor(
                        holder.itemView.context,
                        R.color.black
                    ) else ContextCompat.getColor(
                    holder.itemView.context,
                    R.color.white
                )
            )
        }
        when (item.online) {
            0 -> {
                holder.getView<LinearLayout>(R.id.linearState)
                    .setBackgroundResource(R.drawable.bg_list_user_offline)
                holder.getView<View>(R.id.viewState)
                    .setBackgroundResource(R.drawable.bg_list_item_round_instructions_offline)
                holder.setText(R.id.textState, "离线")
            }
            1 -> {

            }
            2 -> {

            }
            3 -> {
                holder.getView<LinearLayout>(R.id.linearState)
                    .setBackgroundResource(R.drawable.bg_list_user_online)
                holder.getView<View>(R.id.viewState)
                    .setBackgroundResource(R.drawable.bg_list_item_round_instructions)
                holder.setText(R.id.textState, "在线")
            }
        }
    }
}